$(function(){
	//初始化日期控件
  	$('#bt, #et').datetimepicker({
  		language: 'zh-CN',
	    format: 'yyyy-mm-dd hh:00',
	    autoclose: true,
	    minuteStep: 1,
	    minView: "day"
	});
	
	//默认加载今天的数据
	var today = formatDate(new Date(nowYear, nowMonth, nowDay));
	$("#begin_time").val(today+" 00:00");
	$("#end_time").val(today+" 23:00");
	
});

//加载列表数据
function loadDatas(s){
	
	if(s=="search"){
		$("#page").val("");
	}

	//页码
	var page = $("#page").val();
	//一页显示的条数
	var pageSize = 40;
	//用户推广号
	var gameId = $("#gameId").val();

	//开始时间
	var begin = $("#begin_time").val();
	//结束时间
	var end = $("#end_time").val();
	//游戏房间
	var room = $("#room").val();

	$.ajax({
		type: "post",
		data: {"page":page, "pageSize":pageSize, "begin":begin, "end":end, "gameId":gameId, "room":room},
		url: "../../../php/player/playerInfo/loadPlayerGoldChangeData.php",
		beforeSend: function(){
			$("#load").css("display","block");
		},
		success: function(msg){

			$("#load").css("display","none");
			
//			console.log(msg);
			
			//房间总输赢表格
			var rooms = msg.roomZsyInfo;
			var roomTableHtml = "";
			if(rooms.length == 0){
				roomTableHtml += "<tr><td colspan='2' align='center'>没查询到符合条件的数据~</td></tr>";
			}else{
				for(var i = 0; i<rooms.length; i++){
					roomTableHtml += "<tr align='center'>";
//					if($.trim(rooms[i].room) == ""){
//						roomTableHtml += "<td>大厅</td>";
//					}else{
//						roomTableHtml += "<td>"+rooms[i].room+"</td>";
//					}
//					roomTableHtml += "<td>"+rooms[i].roomZsy+"</td>";
					if($.trim(rooms[i].room) != ""){
						roomTableHtml += "<td>"+rooms[i].room+"</td>";
						roomTableHtml += "<td>"+rooms[i].roomZsy+"</td>";
					}
					roomTableHtml += "</tr>";
				}
			}
			
			//救济金
			var alms = msg.alms;
			roomTableHtml += "<tr align='center'><td><b>救济金</b></td><td><b>"+(alms==""?"0":alms)+"</b></td></tr>";
			
			//管理员修改
			var adminAdd = msg.adminAdd;
			roomTableHtml += "<tr align='center'><td><b>管理员修改</b></td><td><b>"+(adminAdd==""?"0":adminAdd)+"</b></td></tr>";
			
			//房间总输赢
			var roomZsy = msg.zsy;
			roomTableHtml += "<tr align='center'><td><b>总输赢</b></td><td><b>"+(roomZsy==""?"0":roomZsy)+"</b></td></tr>";
			
			//资产
			roomTableHtml += "<tr align='center'><td><b>资产</b></td><td><b>"+msg.scoreInfo[0].score+"</b></td></tr>";
			//金币
			roomTableHtml += "<tr align='center'><td><b>金币</b></td><td><b>"+msg.scoreInfo[0].gold+"</b></td></tr>";
			//鱼金币
			roomTableHtml += "<tr align='center'><td><b>鱼币</b></td><td><b>"+msg.scoreInfo[0].fishGold+"</b></td></tr>";
			
			$("#roomZsyDataTablebody").html(roomTableHtml);
			
			//用户信息
			var userInfo = msg.userInfo;
			$("#tgh").html(userInfo[0].gameId==""?"-":"<a href='./playerDetailsInfo.php?gameId="+userInfo[0].gameId+"' title='查看玩家详情'>"+userInfo[0].gameId+"</a>");
			$("#nickName").html(userInfo[0].nickName==""?"-":"<a href='./playerDetailsInfo.php?gameId="+userInfo[0].gameId+"' title='查看玩家详情'>"+userInfo[0].nickName+"</a>");
			$("#userid").html(userInfo[0].userId==""?"-":userInfo[0].userId);
			
			//金币总变动
			var scoreZbd = msg.scoreZbd;
			$("#zbd").html(scoreZbd==""?"0":scoreZbd);
			
			//表格数据
			var datas = msg.records;
			var html = "";
			if(datas.length == 0){
				html += "<tr><td colspan='5' align='center'>暂无数据~</td></tr>";
			}else{
				for(var i = 0; i<datas.length; i++){
					html += "<tr>";
					html += "<td>"+datas[i].time+"</td>";//时间
					var roomName = datas[i].roomName;//房间名
					var content = datas[i].content;//描述
					var scoreChange = datas[i].scoreChange;//金币变化
					if(scoreChange < 0){
						scoreChange = "<b style='font-weight:bold; color:red;'>"+scoreChange+"</b>";
					}else{
						scoreChange = "<b style='font-weight:bold;'>"+scoreChange+"</b>";
					}
					var miaoshu = "";
					if($.trim(roomName) != ""){
						miaoshu += roomName+",";
					}
					html += "<td>"+miaoshu+content+","+scoreChange+"</td>";//描述
					html += "<td>"+scoreChange+"</td>";//金币变化
					html += "<td>"+datas[i].beforeChange+"</td>";//变动前金币
					html += "<td>"+datas[i].afterChange+"</td>";//变动后金币
					html += "</tr>";
				}
			}
			$("#databody").html(html);
			
			//分页数据
			var pageInfos = msg.pageInfo;
			//总条数
			var allCount = pageInfos[0].count;
			$("#count").html(allCount);
			//总页数
			var allPage = Math.ceil(allCount/pageSize);
			if(allPage==0){
				allPage = 1;
			}
			//当前页码
			var now = pageInfos[0].page;
			
			$("#page").val(now);
			$("#nowPage").html(now);
			$("#allPage").html(allPage);
			$("#pageIpu").val("");
		}
	});
}